<template>
  <div class="layout-container">
    <inc-header>
      <div slot="nav" />
    </inc-header>
    <div class="w">
      <div class="content">
        <div class="account-sidebar">
          <div class="avatar gray-box ">
            <div>
              <img :src="avatar"> <h5>{{ userName }}</h5>
            </div>
            <div class="box-inner">
              <ul class="account-nav">
                <li v-for="(item,i) in nav" :key="i" :class="{current:item.name===title}" @click="tab(item)">
                  <a href="javascript:;">{{ item.name }}</a></li>
              </ul>
            </div>
          </div>
        </div>
        <div class="account-content">
          <router-view />
        </div>
      </div>
    </div>
    <inc-footer />
  </div>

</template>
<script>
import IncHeader from '@/views/inc-header'
import IncFooter from '@/views/inc-footer'
import { mapGetters } from 'vuex'

export default {
  components: {
    IncHeader,
    IncFooter
  },
  data() {
    return {
      title: '我的订单',
      nav: [
        { name: '我的订单', path: 'orderList' },
        { name: '我的提案', path: 'quoteList' },
        { name: '账户资料', path: 'userProfile' },
        { name: '修改密码', path: 'updatePassword' }
      ],
      editAvatar: true
    }
  },
  computed: {
    ...mapGetters([
      'userId',
      'userName',
      'avatar'
    ])
  },
  watch: {
    $route(to) {
      const path = to.path.split('/')[2]
      this.nav.forEach(item => {
        if (item.path === path) {
          this.title = item.name
        }
      })
    }
  },
  created() {
    const path = this.$route.path.split('/')[2]
    this.nav.forEach(item => {
      if (item.path === path) {
        this.title = item.name
      }
    })
  },
  methods: {
    tab(e) {
      this.$router.push({ path: '/user/' + e.path })
    }
  }
}
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
@import "../../styles/mixin";

.w {
  padding-top: 40px;
}

.content {
  display: flex;
  height: 100%;
}

.account-sidebar {
  width: 210px;
  border-radius: 6px;
  .avatar {
    padding-top: 20px;
    border-radius: 10px;
    text-align: center;
    img {
      width: 168px;
      height: 168px;
    }
    h5 {
      font-size: 18px;
      line-height: 48px;
      font-weight: 700;
    }
  }
  .account-nav {
    padding-top: 15px;
    li {
      position: relative;
      height: 48px;
      border-top: 1px solid #EBEBEB;
      line-height: 48px;
      &:hover {
        a {
          position: relative;
          z-index: 1;
          height: 50px;
          background-color: #98AFEE;
          line-height: 50px;
          color: #FFF;
        }

      }
      a {
        display: block;
      }
      &.current {
        a {
          position: relative;
          z-index: 1;
          height: 50px;
          background-color: #98AFEE;
          line-height: 50px;
          color: #FFF;
        }
      }

    }
  }
}

.account-content {
  margin-left: 20px;
  flex: 1;
}
</style>
